home *** CD-ROM | disk | FTP | other *** search
- //------------------------------------------------------------------------------
- // File: $$DLL_NAME$$.cpp
- //
- // Desc: DirectMusicTool Wizard generated code - Implementation of DLL Exports.
- //
- // Copyright (c) Microsoft Corporation. All rights reserved.
- //------------------------------------------------------------------------------
-
- #if _MSC_VER > 1000
- #pragma once
- #endif // _MSC_VER > 1000
-
- #define STRICT
- #ifndef _WIN32_WINNT
- #define _WIN32_WINNT 0x0400
- #endif
-
- #define _ATL_FREE_THREADED
- #define _ATL_STATIC_REGISTRY
-
- #include <atlbase.h>
- //You may derive a class from CComModule and use it if you want to override
- //something, but do not change the name of _Module
- extern CComModule _Module;
- #include <atlcom.h>
- #include <atlctl.h>
- #include <statreg.h>
- #include <statreg.cpp>
- #include <atlimpl.cpp>
-
- #include "resource.h"
- #include <initguid.h>
-
- #include "$$CLASS_NAME$$.h"
- $$IF(SUPPORT_DM_DMP)
- #include "$$CLASS_NAME$$Prop.h"
- $$ENDIF
-
- CComModule _Module;
-
- BEGIN_OBJECT_MAP(ObjectMap)
- OBJECT_ENTRY(CLSID_$$TOOL_DEFINE$$, $$CLASS_NAME$$)
- $$IF(SUPPORT_DM_DMP)
- OBJECT_ENTRY(CLSID_$$TOOL_DEFINE$$PROP, $$CLASS_NAME$$Prop)
- $$ENDIF
- END_OBJECT_MAP()
-
- #define CLSID_STRING_SIZE 39
- HRESULT CLSIDToStr(const CLSID &clsid, TCHAR *szStr, int cbStr)
- {
- if(cbStr < CLSID_STRING_SIZE)
- {
- return E_INVALIDARG;
- };
-
- LPOLESTR wszCLSID = NULL;
- HRESULT hr = StringFromCLSID(clsid, &wszCLSID);
- if (!SUCCEEDED(hr)) {
- return hr;
- }
-
- #ifdef UNICODE
- lstrcpy(szStr, wszCLSID);
- #else
- // Covert from wide characters to non-wide.
- wcstombs(szStr, wszCLSID, cbStr);
- #endif
-
- // Free memory.
- CoTaskMemFree(wszCLSID);
-
- return S_OK;
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // Tool information for tool registration in the registry
-
- // TODO: You may modify the fields to your preferred names and description
- TCHAR g_szToolFriendlyName[] = TEXT("$$TOOL_NAME$$");
- TCHAR g_szToolShortName[] = TEXT("$$DLL_NAME$$");
- TCHAR g_szToolDescription[] = TEXT("$$TOOL_DESC$$");
- TCHAR g_szToolVerIndProgID[] = TEXT("$$DLL_NAME$$");
- TCHAR g_szToolProgID[] = TEXT("$$DLL_NAME$$.1");
-
- // Used for tool registration
- const TCHAR cszToolRegRoot[] = TEXT(DMUS_REGSTR_PATH_TOOLS) TEXT("\\");
- const TCHAR cszDescriptionKey[] = TEXT("Description");
- const TCHAR cszNameKey[] = TEXT("Name");
- const TCHAR cszShortNameKey[] = TEXT("ShortName");
-
- HRESULT CLSIDToStr(const CLSID &clsid, TCHAR *szStr, int cbStr);
-
- /////////////////////////////////////////////////////////////////////////////
- // RegisterTool - Adds tool entry to the system registry
-
- HRESULT RegisterTool(REFGUID guid,
- const TCHAR szDescription[],
- const TCHAR szShortName[],
- const TCHAR szName[])
- {
- HKEY hk;
- TCHAR szCLSID[CLSID_STRING_SIZE];
- TCHAR szRegKey[256];
-
- HRESULT hr = CLSIDToStr(guid, szCLSID, sizeof(szCLSID));
- if (!SUCCEEDED(hr))
- {
- return hr;
- }
-
- lstrcpy(szRegKey, cszToolRegRoot);
- lstrcat(szRegKey, szCLSID);
-
- if (RegCreateKey(HKEY_LOCAL_MACHINE,
- szRegKey,
- &hk))
- {
- return E_FAIL;
- }
-
- hr = S_OK;
-
- if (RegSetValueEx(hk,
- cszDescriptionKey,
- 0L,
- REG_SZ,
- (CONST BYTE*)szDescription,
- lstrlen(szDescription) + 1))
- {
- hr = E_FAIL;
- }
-
- if (RegSetValueEx(hk,
- cszNameKey,
- 0L,
- REG_SZ,
- (CONST BYTE*)szName,
- lstrlen(szName) + 1))
- {
- hr = E_FAIL;
- }
-
- if (RegSetValueEx(hk,
- cszShortNameKey,
- 0L,
- REG_SZ,
- (CONST BYTE*)szShortName,
- lstrlen(szName) + 1))
- {
- hr = E_FAIL;
- }
-
- RegCloseKey(hk);
- return hr;
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // UnregisterTool - Removes tool entry from the system registry
-
- HRESULT UnregisterTool(REFGUID guid)
- {
- HKEY hk;
- TCHAR szCLSID[CLSID_STRING_SIZE];
- TCHAR szRegKey[256];
-
- HRESULT hr = CLSIDToStr(guid, szCLSID, sizeof(szCLSID));
- if (!SUCCEEDED(hr))
- {
- return hr;
- }
-
- lstrcpy(szRegKey, cszToolRegRoot);
- lstrcat(szRegKey, szCLSID);
-
- if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,szRegKey,0,KEY_ALL_ACCESS | KEY_WRITE, &hk))
- {
- return E_FAIL;
- }
-
- hr = S_OK;
-
- if (RegDeleteValue(hk,cszDescriptionKey))
- {
- hr = E_FAIL;
- }
-
- if (RegDeleteValue(hk,cszNameKey))
- {
- hr = E_FAIL;
- }
-
- if (RegDeleteValue(hk,cszShortNameKey))
- {
- hr = E_FAIL;
- }
-
- RegCloseKey(hk);
-
- if (RegDeleteKey(HKEY_LOCAL_MACHINE,szRegKey))
- {
- hr = E_FAIL;
- }
-
- return hr;
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // DLL Entry Point
-
- extern "C"
- BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
- {
- if (dwReason == DLL_PROCESS_ATTACH)
- {
- _Module.Init(ObjectMap, hInstance);
- DisableThreadLibraryCalls(hInstance);
- }
- else if (dwReason == DLL_PROCESS_DETACH)
- _Module.Term();
- return TRUE; // ok
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // Used to determine whether the DLL can be unloaded by OLE
-
- STDAPI DllCanUnloadNow(void)
- {
- return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // Returns a class factory to create an object of the requested type
-
- STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
- {
- return _Module.GetClassObject(rclsid, riid, ppv);
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // DllRegisterServer - Adds entries to the system registry
-
- STDAPI DllRegisterServer(void)
- {
- RegisterTool(CLSID_$$TOOL_DEFINE$$,
- g_szToolDescription,
- g_szToolShortName,
- g_szToolFriendlyName);
-
- // registers object
- return _Module.RegisterServer();
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // DllUnregisterServer - Removes entries from the system registry
-
- STDAPI DllUnregisterServer(void)
- {
- UnregisterTool(CLSID_$$TOOL_DEFINE$$);
-
- // unregisters object
- return _Module.UnregisterServer();
- }
-
-